<?php

class Adept_Component_Root extends Adept_Component_Composite 
{
    protected $phaseListeners = array();
    protected $uniqueId;
    
    public function __construct($uniqueId = null) 
    {
        parent::__construct();
        $this->id = '_root';
        $this->uniqueId = $uniqueId;
    }    
    
    public function getParent() 
    {
        return null;
    }    
    
    public function getRoot() 
    {
    	return $this;
    }	
    
    public function getUniqueId()
    {
        return $this->uniqueId;
    }
    
    public function setUniqueId($uniqueId) 
    {
        $this->uniqueId = $uniqueId;
    }    
    
    public function addPhaseListener($phaseId, $listener) 
    {
        $this->phaseListeners[$phaseId][] = $listener;
    }        
    
    public function getPhaseListeners($phaseId) 
    {
        return (isset($this->phaseListeners[$phaseId])) ?
            $this->phaseListeners[$phaseId] : array();
    }    

    public function processRestore() 
    {
        $session = $this->getContext()->getSession();        
        $persistents = $this->findChildrenByClass('Adept_Component_IPersistent');
        foreach ($persistents as $persistent) {
            $persistent->processRestore();
        }
    }    
    
    public function processValidate()
    {
        Adept_ClassKit_Delegate_List::invokeAll($this->getPhaseListeners(Adept_Lifecycle::VALIDATE_PHASE), 
            array());
    }
    
    public function processUpdate() 
    {
        Adept_ClassKit_Delegate_List::invokeAll($this->getPhaseListeners(Adept_Lifecycle::UPDATE_PHASE), 
            array());   
    }    
    
    public function processEvent() 
    {
        Adept_ClassKit_Delegate_List::invokeAll($this->getPhaseListeners(Adept_Lifecycle::EVENT_PHASE), 
            array());
    }    
        
    public function processSave() 
    {
        $session = $this->getContext()->getSession();        
        $persistents = $this->findChildrenByClass('Adept_Component_IPersistent');
        foreach ($persistents as $persistent) {
            $persistent->processSave();
        }
    }    
    
}